﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using HslCommunication.Core;
using HslCommunication.Core.Address;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.Melsec
{
	/// <summary>
	/// 三菱PLC通讯类，采用Qna兼容3E帧协议实现，需要在PLC侧先的以太网模块先进行配置，必须为二进制通讯<br />
	/// Mitsubishi PLC communication class is implemented using Qna compatible 3E frame protocol. 
	/// The Ethernet module on the PLC side needs to be configured first. It must be binary communication.
	/// </summary>
	/// <remarks>
	/// 目前组件测试通过的PLC型号列表，有些来自于网友的测试
	/// <list type="number">
	/// <item>Q06UDV PLC  感谢hwdq0012</item>
	/// <item>fx5u PLC  感谢山楂</item>
	/// <item>Q02CPU PLC </item>
	/// <item>L02CPU PLC </item>
	/// </list>
	/// 地址的输入的格式支持多种复杂的地址表示方式：
	/// <list type="number">
	/// <item>[商业授权] 扩展的数据地址: 表示为 ext=1;W100  访问扩展区域为1的W100的地址信息</item>
	/// <item>[商业授权] 缓冲存储器地址: 表示为 mem=32  访问地址为32的本站缓冲存储器地址</item>
	/// <item>[商业授权] 智能模块地址：表示为 module=3;4106  访问模块号3，偏移地址是4106的数据，偏移地址需要根据模块的详细信息来确认。</item>
	/// <item>[商业授权] 基于标签的地址: 表示位 s=AAA  假如标签的名称为AAA，但是标签的读取是有条件的，详细参照<see cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadTags(System.String,System.UInt16)" /></item>
	/// <item>普通的数据地址，参照下面的信息</item>
	/// </list>
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>内部继电器</term>
	///     <term>M</term>
	///     <term>M100,M200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输入继电器</term>
	///     <term>X</term>
	///     <term>X100,X1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>输出继电器</term>
	///     <term>Y</term>
	///     <term>Y100,Y1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///    <item>
	///     <term>锁存继电器</term>
	///     <term>L</term>
	///     <term>L100,L200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>报警器</term>
	///     <term>F</term>
	///     <term>F100,F200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>边沿继电器</term>
	///     <term>V</term>
	///     <term>V100,V200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>链接继电器</term>
	///     <term>B</term>
	///     <term>B100,B1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>步进继电器</term>
	///     <term>S</term>
	///     <term>S100,S200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>数据寄存器</term>
	///     <term>D</term>
	///     <term>D1000,D2000</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>链接寄存器</term>
	///     <term>W</term>
	///     <term>W100,W1A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>文件寄存器</term>
	///     <term>R</term>
	///     <term>R100,R200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>ZR文件寄存器</term>
	///     <term>ZR</term>
	///     <term>ZR100,ZR2A0</term>
	///     <term>16</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>变址寄存器</term>
	///     <term>Z</term>
	///     <term>Z100,Z200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的触点</term>
	///     <term>TS</term>
	///     <term>TS100,TS200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的线圈</term>
	///     <term>TC</term>
	///     <term>TC100,TC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>定时器的当前值</term>
	///     <term>TN</term>
	///     <term>TN100,TN200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>累计定时器的触点</term>
	///     <term>SS</term>
	///     <term>SS100,SS200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>累计定时器的线圈</term>
	///     <term>SC</term>
	///     <term>SC100,SC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>累计定时器的当前值</term>
	///     <term>SN</term>
	///     <term>SN100,SN200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的触点</term>
	///     <term>CS</term>
	///     <term>CS100,CS200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的线圈</term>
	///     <term>CC</term>
	///     <term>CC100,CC200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>计数器的当前值</term>
	///     <term>CN</term>
	///     <term>CN100,CN200</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>×</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// </remarks>
	/// <example>
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="Usage" title="简单的短连接使用" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="Usage2" title="简单的长连接使用" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="ReadExample1" title="基本的读取示例" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="ReadExample2" title="批量读取示例" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="ReadExample3" title="随机字读取示例" />
	/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="ReadExample4" title="随机批量字读取示例" />
	/// </example>
	// Token: 0x02000073 RID: 115
	public class MelsecMcNet : NetworkDeviceBase
	{
		/// <summary>
		/// 实例化三菱的Qna兼容3E帧协议的通讯对象<br />
		/// Instantiate the communication object of Mitsubishi's Qna compatible 3E frame protocol
		/// </summary>
		// Token: 0x06000960 RID: 2400 RVA: 0x000366D4 File Offset: 0x000348D4
		public MelsecMcNet()
		{
			base.WordLength = 1;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// 指定ip地址和端口号来实例化一个默认的对象<br />
		/// Specify the IP address and port number to instantiate a default object
		/// </summary>
		/// <param name="ipAddress">PLC的Ip地址</param>
		/// <param name="port">PLC的端口</param>
		// Token: 0x06000961 RID: 2401 RVA: 0x00036700 File Offset: 0x00034900
		public MelsecMcNet(string ipAddress, int port)
		{
			base.WordLength = 1;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <inheritdoc />
		// Token: 0x06000962 RID: 2402 RVA: 0x00034D9A File Offset: 0x00032F9A
		protected override INetMessage GetNewNetMessage()
		{
			return new MelsecQnA3EBinaryMessage();
		}

		/// <summary>
		/// 网络号，通常为0<br />
		/// Network number, usually 0
		/// </summary>
		/// <remarks>
		/// 依据PLC的配置而配置，如果PLC配置了1，那么此处也填0，如果PLC配置了2，此处就填2，测试不通的话，继续测试0
		/// </remarks>
		// Token: 0x17000197 RID: 407
		// (get) Token: 0x06000963 RID: 2403 RVA: 0x0003673C File Offset: 0x0003493C
		// (set) Token: 0x06000964 RID: 2404 RVA: 0x00036744 File Offset: 0x00034944
		public byte NetworkNumber { get; set; } = 0;

		/// <summary>
		/// 网络站号，通常为0<br />
		/// Network station number, usually 0
		/// </summary>
		/// <remarks>
		/// 依据PLC的配置而配置，如果PLC配置了1，那么此处也填0，如果PLC配置了2，此处就填2，测试不通的话，继续测试0
		/// </remarks>
		// Token: 0x17000198 RID: 408
		// (get) Token: 0x06000965 RID: 2405 RVA: 0x0003674D File Offset: 0x0003494D
		// (set) Token: 0x06000966 RID: 2406 RVA: 0x00036755 File Offset: 0x00034955
		public byte NetworkStationNumber { get; set; } = 0;

		/// <summary>
		/// 当前MC协议的分析地址的方法，对传入的字符串格式的地址进行数据解析。<br />
		/// The current MC protocol's address analysis method performs data parsing on the address of the incoming string format.
		/// </summary>
		/// <param name="address">地址信息</param>
		/// <param name="length">数据长度</param>
		/// <returns>解析后的数据信息</returns>
		// Token: 0x06000967 RID: 2407 RVA: 0x0003299A File Offset: 0x00030B9A
		protected virtual OperateResult<McAddressData> McAnalysisAddress(string address, ushort length)
		{
			return McAddressData.ParseMelsecFrom(address, length);
		}

		/// <inheritdoc />
		// Token: 0x06000968 RID: 2408 RVA: 0x00036760 File Offset: 0x00034960
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			bool flag = address.StartsWith("s=") || address.StartsWith("S=");
			OperateResult<byte[]> result;
			if (flag)
			{
				result = this.ReadTags(address.Substring(2), length);
			}
			else
			{
				bool flag2 = Regex.IsMatch(address, "ext=[0-9]+;", RegexOptions.IgnoreCase);
				if (flag2)
				{
					string value = Regex.Match(address, "ext=[0-9]+;").Value;
					ushort extend = ushort.Parse(Regex.Match(value, "[0-9]+").Value);
					result = this.ReadExtend(extend, address.Substring(value.Length), length);
				}
				else
				{
					bool flag3 = Regex.IsMatch(address, "mem=", RegexOptions.IgnoreCase);
					if (flag3)
					{
						result = this.ReadMemory(address.Substring(4), length);
					}
					else
					{
						bool flag4 = Regex.IsMatch(address, "module=[0-9]+;", RegexOptions.IgnoreCase);
						if (flag4)
						{
							string value2 = Regex.Match(address, "module=[0-9]+;").Value;
							ushort module = ushort.Parse(Regex.Match(value2, "[0-9]+").Value);
							result = this.ReadSmartModule(module, address.Substring(value2.Length), length * 2);
						}
						else
						{
							OperateResult<McAddressData> operateResult = this.McAnalysisAddress(address, length);
							bool flag5 = !operateResult.IsSuccess;
							if (flag5)
							{
								result = OperateResult.CreateFailedResult<byte[]>(operateResult);
							}
							else
							{
								List<byte> list = new List<byte>();
								ushort num = 0;
								while (num < length)
								{
									ushort num2 = (ushort)Math.Min((int)(length - num), 900);
									operateResult.Content.Length = num2;
									OperateResult<byte[]> operateResult2 = this.ReadAddressData(operateResult.Content);
									bool flag6 = !operateResult2.IsSuccess;
									if (flag6)
									{
										return operateResult2;
									}
									list.AddRange(operateResult2.Content);
									num += num2;
									bool flag7 = operateResult.Content.McDataType.DataType == 0;
									if (flag7)
									{
										operateResult.Content.AddressStart += (int)num2;
									}
									else
									{
										operateResult.Content.AddressStart += (int)(num2 * 16);
									}
								}
								result = OperateResult.CreateSuccessResult<byte[]>(list.ToArray());
							}
						}
					}
				}
			}
			return result;
		}

		// Token: 0x06000969 RID: 2409 RVA: 0x0003697C File Offset: 0x00034B7C
		private OperateResult<byte[]> ReadAddressData(McAddressData addressData)
		{
			byte[] mcCore = MelsecHelper.BuildReadMcCoreCommand(addressData, false);
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					result = MelsecMcNet.ExtractActualData(operateResult.Content.RemoveBegin(11), false);
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600096A RID: 2410 RVA: 0x00036A00 File Offset: 0x00034C00
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<McAddressData> operateResult = this.McAnalysisAddress(address, 0);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				result = this.WriteAddressData(operateResult.Content, value);
			}
			return result;
		}

		// Token: 0x0600096B RID: 2411 RVA: 0x00036A40 File Offset: 0x00034C40
		private OperateResult WriteAddressData(McAddressData addressData, byte[] value)
		{
			byte[] mcCore = MelsecHelper.BuildWriteWordCoreCommand(addressData, value);
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x0600096C RID: 2412 RVA: 0x00036AB4 File Offset: 0x00034CB4
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			MelsecMcNet.<ReadAsync>d__16 <ReadAsync>d__ = new MelsecMcNet.<ReadAsync>d__16();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadAsync>d__16>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		// Token: 0x0600096D RID: 2413 RVA: 0x00036B08 File Offset: 0x00034D08
		[DebuggerStepThrough]
		private Task<OperateResult<byte[]>> ReadAddressDataAsync(McAddressData addressData)
		{
			MelsecMcNet.<ReadAddressDataAsync>d__17 <ReadAddressDataAsync>d__ = new MelsecMcNet.<ReadAddressDataAsync>d__17();
			<ReadAddressDataAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAddressDataAsync>d__.<>4__this = this;
			<ReadAddressDataAsync>d__.addressData = addressData;
			<ReadAddressDataAsync>d__.<>1__state = -1;
			<ReadAddressDataAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadAddressDataAsync>d__17>(ref <ReadAddressDataAsync>d__);
			return <ReadAddressDataAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x0600096E RID: 2414 RVA: 0x00036B54 File Offset: 0x00034D54
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			MelsecMcNet.<WriteAsync>d__18 <WriteAsync>d__ = new MelsecMcNet.<WriteAsync>d__18();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecMcNet.<WriteAsync>d__18>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		// Token: 0x0600096F RID: 2415 RVA: 0x00036BA8 File Offset: 0x00034DA8
		[DebuggerStepThrough]
		private Task<OperateResult> WriteAddressDataAsync(McAddressData addressData, byte[] value)
		{
			MelsecMcNet.<WriteAddressDataAsync>d__19 <WriteAddressDataAsync>d__ = new MelsecMcNet.<WriteAddressDataAsync>d__19();
			<WriteAddressDataAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAddressDataAsync>d__.<>4__this = this;
			<WriteAddressDataAsync>d__.addressData = addressData;
			<WriteAddressDataAsync>d__.value = value;
			<WriteAddressDataAsync>d__.<>1__state = -1;
			<WriteAddressDataAsync>d__.<>t__builder.Start<MelsecMcNet.<WriteAddressDataAsync>d__19>(ref <WriteAddressDataAsync>d__);
			return <WriteAddressDataAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 随机读取PLC的数据信息，可以跨地址，跨类型组合，但是每个地址只能读取一个word，也就是2个字节的内容。收到结果后，需要自行解析数据<br />
		/// Randomly read PLC data information, which can be combined across addresses and types, but each address can only read one word, 
		/// which is the content of 2 bytes. After receiving the results, you need to parse the data yourself
		/// </summary>
		/// <param name="address">所有的地址的集合</param>
		/// <remarks>
		/// 访问安装有 Q 系列 C24/E71 的站 QCPU 上位站 经由 Q 系列兼容网络系统 MELSECNET/H MELSECNET/10 Ethernet 的 QCPU 其他站 时
		/// 访问点数········1≦ 字访问点数 双字访问点数 ≦192
		/// <br />
		/// 访问 QnACPU 其他站 经由 QnA 系列兼容网络系统 MELSECNET/10 Ethernet 的 Q/QnACPU 其他站 时访问点数········1≦ 字访问点数 双字访问点数 ≦96
		/// <br />
		/// 访问上述以外的 PLC CPU 其他站 时访问点数········1≦字访问点数≦10
		/// </remarks>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="ReadExample3" title="随机字读取示例" /></example>
		/// <returns>结果</returns>
		// Token: 0x06000970 RID: 2416 RVA: 0x00036BFC File Offset: 0x00034DFC
		public OperateResult<byte[]> ReadRandom(string[] address)
		{
			McAddressData[] array = new McAddressData[address.Length];
			for (int i = 0; i < address.Length; i++)
			{
				OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address[i], 1);
				bool flag = !operateResult.IsSuccess;
				if (flag)
				{
					return OperateResult.CreateFailedResult<byte[]>(operateResult);
				}
				array[i] = operateResult.Content;
			}
			byte[] mcCore = MelsecHelper.BuildReadRandomWordCommand(array);
			OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
			bool flag2 = !operateResult2.IsSuccess;
			if (flag2)
			{
				return OperateResult.CreateFailedResult<byte[]>(operateResult2);
			}
			OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
			bool flag3 = !operateResult3.IsSuccess;
			if (flag3)
			{
				return OperateResult.CreateFailedResult<byte[]>(operateResult3);
			}
			return MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), false);
		}

		/// <summary>
		/// 随机读取PLC的数据信息，可以跨地址，跨类型组合，每个地址是任意的长度。收到结果后，需要自行解析数据，目前只支持字地址，比如D区，W区，R区，不支持X，Y，M，B，L等等<br />
		/// Read the data information of the PLC randomly. It can be combined across addresses and types. Each address is of any length. After receiving the results, 
		/// you need to parse the data yourself. Currently, only word addresses are supported, such as D area, W area, R area. X, Y, M, B, L, etc
		/// </summary>
		/// <param name="address">所有的地址的集合</param>
		/// <param name="length">每个地址的长度信息</param>
		/// <remarks>
		/// 实际测试不一定所有的plc都可以读取成功，具体情况需要具体分析
		/// <br />
		/// 1 块数按照下列要求指定 120 ≧ 字软元件块数 + 位软元件块数
		/// <br />
		/// 2 各软元件点数按照下列要求指定 960 ≧ 字软元件各块的合计点数 + 位软元件各块的合计点数
		/// </remarks>
		/// <example>
		/// <code lang="cs" source="HslCommunication_Net45.Test\Documentation\Samples\Profinet\melsecTest.cs" region="ReadExample4" title="随机批量字读取示例" />
		/// </example>
		/// <returns>结果</returns>
		// Token: 0x06000971 RID: 2417 RVA: 0x00036CDC File Offset: 0x00034EDC
		public OperateResult<byte[]> ReadRandom(string[] address, ushort[] length)
		{
			bool flag = length.Length != address.Length;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(StringResources.Language.TwoParametersLengthIsNotSame);
			}
			else
			{
				McAddressData[] array = new McAddressData[address.Length];
				for (int i = 0; i < address.Length; i++)
				{
					OperateResult<McAddressData> operateResult = McAddressData.ParseMelsecFrom(address[i], length[i]);
					bool flag2 = !operateResult.IsSuccess;
					if (flag2)
					{
						return OperateResult.CreateFailedResult<byte[]>(operateResult);
					}
					array[i] = operateResult.Content;
				}
				byte[] mcCore = MelsecHelper.BuildReadRandomCommand(array);
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
				bool flag3 = !operateResult2.IsSuccess;
				if (flag3)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
					bool flag4 = !operateResult3.IsSuccess;
					if (flag4)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
					}
					else
					{
						result = MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), false);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// 随机读取PLC的数据信息，可以跨地址，跨类型组合，但是每个地址只能读取一个word，也就是2个字节的内容。收到结果后，自动转换为了short类型的数组<br />
		/// Randomly read PLC data information, which can be combined across addresses and types, but each address can only read one word, 
		/// which is the content of 2 bytes. After receiving the result, it is automatically converted to an array of type short.
		/// </summary>
		/// <param name="address">所有的地址的集合</param>
		/// <remarks>
		/// 访问安装有 Q 系列 C24/E71 的站 QCPU 上位站 经由 Q 系列兼容网络系统 MELSECNET/H MELSECNET/10 Ethernet 的 QCPU 其他站 时
		/// 访问点数········1≦ 字访问点数 双字访问点数 ≦192
		///
		/// 访问 QnACPU 其他站 经由 QnA 系列兼容网络系统 MELSECNET/10 Ethernet 的 Q/QnACPU 其他站 时访问点数········1≦ 字访问点数 双字访问点数 ≦96
		///
		/// 访问上述以外的 PLC CPU 其他站 时访问点数········1≦字访问点数≦10
		/// </remarks>
		/// <returns>结果</returns>
		// Token: 0x06000972 RID: 2418 RVA: 0x00036DE4 File Offset: 0x00034FE4
		public OperateResult<short[]> ReadRandomInt16(string[] address)
		{
			OperateResult<byte[]> operateResult = this.ReadRandom(address);
			bool flag = !operateResult.IsSuccess;
			OperateResult<short[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<short[]>(operateResult);
			}
			else
			{
				result = OperateResult.CreateSuccessResult<short[]>(base.ByteTransform.TransInt16(operateResult.Content, 0, address.Length));
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadRandom(System.String[])" />
		// Token: 0x06000973 RID: 2419 RVA: 0x00036E30 File Offset: 0x00035030
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadRandomAsync(string[] address)
		{
			MelsecMcNet.<ReadRandomAsync>d__23 <ReadRandomAsync>d__ = new MelsecMcNet.<ReadRandomAsync>d__23();
			<ReadRandomAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadRandomAsync>d__.<>4__this = this;
			<ReadRandomAsync>d__.address = address;
			<ReadRandomAsync>d__.<>1__state = -1;
			<ReadRandomAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadRandomAsync>d__23>(ref <ReadRandomAsync>d__);
			return <ReadRandomAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadRandom(System.String[],System.UInt16[])" />
		// Token: 0x06000974 RID: 2420 RVA: 0x00036E7C File Offset: 0x0003507C
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadRandomAsync(string[] address, ushort[] length)
		{
			MelsecMcNet.<ReadRandomAsync>d__24 <ReadRandomAsync>d__ = new MelsecMcNet.<ReadRandomAsync>d__24();
			<ReadRandomAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadRandomAsync>d__.<>4__this = this;
			<ReadRandomAsync>d__.address = address;
			<ReadRandomAsync>d__.length = length;
			<ReadRandomAsync>d__.<>1__state = -1;
			<ReadRandomAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadRandomAsync>d__24>(ref <ReadRandomAsync>d__);
			return <ReadRandomAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadRandomInt16(System.String[])" />
		// Token: 0x06000975 RID: 2421 RVA: 0x00036ED0 File Offset: 0x000350D0
		[DebuggerStepThrough]
		public Task<OperateResult<short[]>> ReadRandomInt16Async(string[] address)
		{
			MelsecMcNet.<ReadRandomInt16Async>d__25 <ReadRandomInt16Async>d__ = new MelsecMcNet.<ReadRandomInt16Async>d__25();
			<ReadRandomInt16Async>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<short[]>>.Create();
			<ReadRandomInt16Async>d__.<>4__this = this;
			<ReadRandomInt16Async>d__.address = address;
			<ReadRandomInt16Async>d__.<>1__state = -1;
			<ReadRandomInt16Async>d__.<>t__builder.Start<MelsecMcNet.<ReadRandomInt16Async>d__25>(ref <ReadRandomInt16Async>d__);
			return <ReadRandomInt16Async>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000976 RID: 2422 RVA: 0x00036F1C File Offset: 0x0003511C
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<McAddressData> operateResult = this.McAnalysisAddress(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				byte[] mcCore = MelsecHelper.BuildReadMcCoreCommand(operateResult.Content, true);
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					else
					{
						OperateResult<byte[]> operateResult4 = MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), true);
						bool flag4 = !operateResult4.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<bool[]>(operateResult4);
						}
						else
						{
							result = OperateResult.CreateSuccessResult<bool[]>(Enumerable.ToArray<bool>(Enumerable.Take<bool>(Enumerable.Select<byte, bool>(operateResult4.Content, (byte m) => m == 1), (int)length)));
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000977 RID: 2423 RVA: 0x00037028 File Offset: 0x00035228
		[HslMqttApi("WriteBoolArray", "")]
		public override OperateResult Write(string address, bool[] values)
		{
			OperateResult<McAddressData> operateResult = this.McAnalysisAddress(address, 0);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				byte[] mcCore = MelsecHelper.BuildWriteBitCoreCommand(operateResult.Content, values);
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = operateResult3;
					}
					else
					{
						result = OperateResult.CreateSuccessResult();
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadBool(System.String,System.UInt16)" />
		// Token: 0x06000978 RID: 2424 RVA: 0x000370B8 File Offset: 0x000352B8
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			MelsecMcNet.<ReadBoolAsync>d__28 <ReadBoolAsync>d__ = new MelsecMcNet.<ReadBoolAsync>d__28();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadBoolAsync>d__28>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.Write(System.String,System.Boolean[])" />
		// Token: 0x06000979 RID: 2425 RVA: 0x0003710C File Offset: 0x0003530C
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool[] values)
		{
			MelsecMcNet.<WriteAsync>d__29 <WriteAsync>d__ = new MelsecMcNet.<WriteAsync>d__29();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.values = values;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<MelsecMcNet.<WriteAsync>d__29>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// <b>[商业授权]</b> 读取PLC的标签信息，需要传入标签的名称，读取的字长度，标签举例：A; label[1]; bbb[10,10,10]<br />
		/// <b>[Authorization]</b> To read the label information of the PLC, you need to pass in the name of the label, 
		/// the length of the word read, and an example of the label: A; label [1]; bbb [10,10,10]
		/// </summary>
		/// <param name="tag">标签名</param>
		/// <param name="length">读取长度</param>
		/// <returns>是否成功</returns>
		/// <remarks>
		///  不可以访问局部标签。<br />
		///  不可以访问通过GX Works2设置的全局标签。<br />
		///  为了访问全局标签，需要通过GX Works3的全局标签设置编辑器将“来自于外部设备的访问”的设置项目置为有效。(默认为无效。)<br />
		///  以ASCII代码进行数据通信时，由于需要从UTF-16将标签名转换为ASCII代码，因此报文容量将增加
		/// </remarks>
		// Token: 0x0600097A RID: 2426 RVA: 0x0003715E File Offset: 0x0003535E
		[HslMqttApi(ApiTopic = "ReadTag", Description = "读取PLC的标签信息，需要传入标签的名称，读取的字长度，标签举例：A; label[1]; bbb[10,10,10]")]
		public OperateResult<byte[]> ReadTags(string tag, ushort length)
		{
			return this.ReadTags(new string[]
			{
				tag
			}, new ushort[]
			{
				length
			});
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadTags(System.String,System.UInt16)" />
		// Token: 0x0600097B RID: 2427 RVA: 0x0003717C File Offset: 0x0003537C
		[HslMqttApi(ApiTopic = "ReadTags", Description = "批量读取PLC的标签信息，需要传入标签的名称，读取的字长度，标签举例：A; label[1]; bbb[10,10,10]")]
		public OperateResult<byte[]> ReadTags(string[] tags, ushort[] length)
		{
			bool flag = !Authorization.asdniasnfaksndiqwhawfskhfaiw();
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(StringResources.Language.InsufficientPrivileges);
			}
			else
			{
				byte[] mcCore = MelsecHelper.BuildReadTag(tags, length);
				OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult);
				}
				else
				{
					OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					else
					{
						OperateResult<byte[]> operateResult3 = MelsecMcNet.ExtractActualData(operateResult.Content.RemoveBegin(11), false);
						bool flag4 = !operateResult3.IsSuccess;
						if (flag4)
						{
							result = operateResult3;
						}
						else
						{
							result = MelsecHelper.ExtraTagData(operateResult3.Content);
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadTags(System.String,System.UInt16)" />
		// Token: 0x0600097C RID: 2428 RVA: 0x00037248 File Offset: 0x00035448
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadTagsAsync(string tag, ushort length)
		{
			MelsecMcNet.<ReadTagsAsync>d__32 <ReadTagsAsync>d__ = new MelsecMcNet.<ReadTagsAsync>d__32();
			<ReadTagsAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadTagsAsync>d__.<>4__this = this;
			<ReadTagsAsync>d__.tag = tag;
			<ReadTagsAsync>d__.length = length;
			<ReadTagsAsync>d__.<>1__state = -1;
			<ReadTagsAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadTagsAsync>d__32>(ref <ReadTagsAsync>d__);
			return <ReadTagsAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadTags(System.String,System.UInt16)" />
		// Token: 0x0600097D RID: 2429 RVA: 0x0003729C File Offset: 0x0003549C
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadTagsAsync(string[] tags, ushort[] length)
		{
			MelsecMcNet.<ReadTagsAsync>d__33 <ReadTagsAsync>d__ = new MelsecMcNet.<ReadTagsAsync>d__33();
			<ReadTagsAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadTagsAsync>d__.<>4__this = this;
			<ReadTagsAsync>d__.tags = tags;
			<ReadTagsAsync>d__.length = length;
			<ReadTagsAsync>d__.<>1__state = -1;
			<ReadTagsAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadTagsAsync>d__33>(ref <ReadTagsAsync>d__);
			return <ReadTagsAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// <b>[商业授权]</b> 读取扩展的数据信息，需要在原有的地址，长度信息之外，输入扩展值信息<br />
		/// <b>[Authorization]</b> To read the extended data information, you need to enter the extended value information in addition to the original address and length information
		/// </summary>
		/// <param name="extend">扩展信息</param>
		/// <param name="address">地址</param>
		/// <param name="length">数据长度</param>
		/// <returns>返回结果</returns>
		// Token: 0x0600097E RID: 2430 RVA: 0x000372F0 File Offset: 0x000354F0
		[HslMqttApi(ApiTopic = "ReadExtend", Description = "读取扩展的数据信息，需要在原有的地址，长度信息之外，输入扩展值信息")]
		public OperateResult<byte[]> ReadExtend(ushort extend, string address, ushort length)
		{
			bool flag = !Authorization.asdniasnfaksndiqwhawfskhfaiw();
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(StringResources.Language.InsufficientPrivileges);
			}
			else
			{
				OperateResult<McAddressData> operateResult = this.McAnalysisAddress(address, length);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult);
				}
				else
				{
					byte[] mcCore = MelsecHelper.BuildReadMcCoreExtendCommand(operateResult.Content, extend, false);
					OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(mcCore, this.NetworkNumber, this.NetworkStationNumber));
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					else
					{
						OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
						bool flag4 = !operateResult3.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
						}
						else
						{
							OperateResult<byte[]> operateResult4 = MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), false);
							bool flag5 = !operateResult4.IsSuccess;
							if (flag5)
							{
								result = operateResult4;
							}
							else
							{
								result = MelsecHelper.ExtraTagData(operateResult4.Content);
							}
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadExtend(System.UInt16,System.String,System.UInt16)" />
		// Token: 0x0600097F RID: 2431 RVA: 0x000373EC File Offset: 0x000355EC
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadExtendAsync(ushort extend, string address, ushort length)
		{
			MelsecMcNet.<ReadExtendAsync>d__35 <ReadExtendAsync>d__ = new MelsecMcNet.<ReadExtendAsync>d__35();
			<ReadExtendAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadExtendAsync>d__.<>4__this = this;
			<ReadExtendAsync>d__.extend = extend;
			<ReadExtendAsync>d__.address = address;
			<ReadExtendAsync>d__.length = length;
			<ReadExtendAsync>d__.<>1__state = -1;
			<ReadExtendAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadExtendAsync>d__35>(ref <ReadExtendAsync>d__);
			return <ReadExtendAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// <b>[商业授权]</b> 读取缓冲寄存器的数据信息，地址直接为偏移地址<br />
		/// <b>[Authorization]</b> Read the data information of the buffer register, the address is directly the offset address
		/// </summary>
		/// <remarks>
		/// 本指令不可以访问下述缓冲存储器:<br />
		/// 1. 本站(SLMP对应设备)上安装的智能功能模块<br />
		/// 2. 其它站缓冲存储器<br />
		/// </remarks>
		/// <param name="address">偏移地址</param>
		/// <param name="length">读取长度</param>
		/// <returns>读取的内容</returns>
		// Token: 0x06000980 RID: 2432 RVA: 0x00037448 File Offset: 0x00035648
		[HslMqttApi(ApiTopic = "ReadMemory", Description = "读取缓冲寄存器的数据信息，地址直接为偏移地址")]
		public OperateResult<byte[]> ReadMemory(string address, ushort length)
		{
			bool flag = !Authorization.asdniasnfaksndiqwhawfskhfaiw();
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(StringResources.Language.InsufficientPrivileges);
			}
			else
			{
				OperateResult<byte[]> operateResult = MelsecHelper.BuildReadMemoryCommand(address, length);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = operateResult;
				}
				else
				{
					OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(operateResult.Content, this.NetworkNumber, this.NetworkStationNumber));
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					else
					{
						OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
						bool flag4 = !operateResult3.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
						}
						else
						{
							result = MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), false);
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadMemory(System.String,System.UInt16)" />
		// Token: 0x06000981 RID: 2433 RVA: 0x0003750C File Offset: 0x0003570C
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadMemoryAsync(string address, ushort length)
		{
			MelsecMcNet.<ReadMemoryAsync>d__37 <ReadMemoryAsync>d__ = new MelsecMcNet.<ReadMemoryAsync>d__37();
			<ReadMemoryAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadMemoryAsync>d__.<>4__this = this;
			<ReadMemoryAsync>d__.address = address;
			<ReadMemoryAsync>d__.length = length;
			<ReadMemoryAsync>d__.<>1__state = -1;
			<ReadMemoryAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadMemoryAsync>d__37>(ref <ReadMemoryAsync>d__);
			return <ReadMemoryAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// <b>[商业授权]</b> 读取智能模块的数据信息，需要指定模块地址，偏移地址，读取的字节长度<br />
		/// <b>[Authorization]</b> To read the extended data information, you need to enter the extended value information in addition to the original address and length information
		/// </summary>
		/// <param name="module">模块地址</param>
		/// <param name="address">地址</param>
		/// <param name="length">数据长度</param>
		/// <returns>返回结果</returns>
		// Token: 0x06000982 RID: 2434 RVA: 0x00037560 File Offset: 0x00035760
		[HslMqttApi(ApiTopic = "ReadSmartModule", Description = "读取智能模块的数据信息，需要指定模块地址，偏移地址，读取的字节长度")]
		public OperateResult<byte[]> ReadSmartModule(ushort module, string address, ushort length)
		{
			bool flag = !Authorization.asdniasnfaksndiqwhawfskhfaiw();
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>(StringResources.Language.InsufficientPrivileges);
			}
			else
			{
				OperateResult<byte[]> operateResult = MelsecHelper.BuildReadSmartModule(module, address, length);
				bool flag2 = !operateResult.IsSuccess;
				if (flag2)
				{
					result = operateResult;
				}
				else
				{
					OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(operateResult.Content, this.NetworkNumber, this.NetworkStationNumber));
					bool flag3 = !operateResult2.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
					}
					else
					{
						OperateResult operateResult3 = MelsecMcNet.CheckResponseContent(operateResult2.Content);
						bool flag4 = !operateResult3.IsSuccess;
						if (flag4)
						{
							result = OperateResult.CreateFailedResult<byte[]>(operateResult3);
						}
						else
						{
							result = MelsecMcNet.ExtractActualData(operateResult2.Content.RemoveBegin(11), false);
						}
					}
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadSmartModule(System.UInt16,System.String,System.UInt16)" />
		// Token: 0x06000983 RID: 2435 RVA: 0x00037624 File Offset: 0x00035824
		[DebuggerStepThrough]
		public Task<OperateResult<byte[]>> ReadSmartModuleAsync(ushort module, string address, ushort length)
		{
			MelsecMcNet.<ReadSmartModuleAsync>d__39 <ReadSmartModuleAsync>d__ = new MelsecMcNet.<ReadSmartModuleAsync>d__39();
			<ReadSmartModuleAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadSmartModuleAsync>d__.<>4__this = this;
			<ReadSmartModuleAsync>d__.module = module;
			<ReadSmartModuleAsync>d__.address = address;
			<ReadSmartModuleAsync>d__.length = length;
			<ReadSmartModuleAsync>d__.<>1__state = -1;
			<ReadSmartModuleAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadSmartModuleAsync>d__39>(ref <ReadSmartModuleAsync>d__);
			return <ReadSmartModuleAsync>d__.<>t__builder.Task;
		}

		/// <summary>
		/// 远程Run操作<br />
		/// Remote Run Operation
		/// </summary>
		/// <param name="force">是否强制执行</param>
		/// <returns>是否成功</returns>
		// Token: 0x06000984 RID: 2436 RVA: 0x00037680 File Offset: 0x00035880
		[HslMqttApi]
		public OperateResult RemoteRun(bool force = false)
		{
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(new byte[]
			{
				1,
				16,
				0,
				0,
				1,
				0,
				0,
				0
			}, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <summary>
		/// 远程Stop操作<br />
		/// Remote Stop operation
		/// </summary>
		/// <returns>是否成功</returns>
		// Token: 0x06000985 RID: 2437 RVA: 0x000376F0 File Offset: 0x000358F0
		[HslMqttApi]
		public OperateResult RemoteStop()
		{
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(new byte[]
			{
				2,
				16,
				0,
				0,
				1,
				0
			}, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <summary>
		/// 远程Reset操作<br />
		/// Remote Reset Operation
		/// </summary>
		/// <returns>是否成功</returns>
		// Token: 0x06000986 RID: 2438 RVA: 0x00037760 File Offset: 0x00035960
		[HslMqttApi]
		public OperateResult RemoteReset()
		{
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(new byte[]
			{
				6,
				16,
				0,
				0,
				1,
				0
			}, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <summary>
		/// 读取PLC的型号信息，例如 Q02HCPU<br />
		/// Read PLC model information, such as Q02HCPU
		/// </summary>
		/// <returns>返回型号的结果对象</returns>
		// Token: 0x06000987 RID: 2439 RVA: 0x000377D0 File Offset: 0x000359D0
		[HslMqttApi]
		public OperateResult<string> ReadPlcType()
		{
			byte[] array = new byte[4];
			array[0] = 1;
			array[1] = 1;
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(array, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult<string> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<string>(operateResult);
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<string>(operateResult2);
				}
				else
				{
					result = OperateResult.CreateSuccessResult<string>(Encoding.ASCII.GetString(operateResult.Content, 11, 16).TrimEnd(new char[0]));
				}
			}
			return result;
		}

		/// <summary>
		/// LED 熄灭 出错代码初始化<br />
		/// LED off Error code initialization
		/// </summary>
		/// <returns>是否成功</returns>
		// Token: 0x06000988 RID: 2440 RVA: 0x00037868 File Offset: 0x00035A68
		[HslMqttApi]
		public OperateResult ErrorStateReset()
		{
			byte[] array = new byte[4];
			array[0] = 23;
			array[1] = 22;
			OperateResult<byte[]> operateResult = base.ReadFromCoreServer(MelsecMcNet.PackMcCommand(array, this.NetworkNumber, this.NetworkStationNumber));
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult operateResult2 = MelsecMcNet.CheckResponseContent(operateResult.Content);
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = operateResult2;
				}
				else
				{
					result = OperateResult.CreateSuccessResult();
				}
			}
			return result;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.RemoteRun(System.Boolean)" />
		// Token: 0x06000989 RID: 2441 RVA: 0x000378D8 File Offset: 0x00035AD8
		[DebuggerStepThrough]
		public Task<OperateResult> RemoteRunAsync()
		{
			MelsecMcNet.<RemoteRunAsync>d__45 <RemoteRunAsync>d__ = new MelsecMcNet.<RemoteRunAsync>d__45();
			<RemoteRunAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<RemoteRunAsync>d__.<>4__this = this;
			<RemoteRunAsync>d__.<>1__state = -1;
			<RemoteRunAsync>d__.<>t__builder.Start<MelsecMcNet.<RemoteRunAsync>d__45>(ref <RemoteRunAsync>d__);
			return <RemoteRunAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.RemoteStop" />
		// Token: 0x0600098A RID: 2442 RVA: 0x0003791C File Offset: 0x00035B1C
		[DebuggerStepThrough]
		public Task<OperateResult> RemoteStopAsync()
		{
			MelsecMcNet.<RemoteStopAsync>d__46 <RemoteStopAsync>d__ = new MelsecMcNet.<RemoteStopAsync>d__46();
			<RemoteStopAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<RemoteStopAsync>d__.<>4__this = this;
			<RemoteStopAsync>d__.<>1__state = -1;
			<RemoteStopAsync>d__.<>t__builder.Start<MelsecMcNet.<RemoteStopAsync>d__46>(ref <RemoteStopAsync>d__);
			return <RemoteStopAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.RemoteReset" />
		// Token: 0x0600098B RID: 2443 RVA: 0x00037960 File Offset: 0x00035B60
		[DebuggerStepThrough]
		public Task<OperateResult> RemoteResetAsync()
		{
			MelsecMcNet.<RemoteResetAsync>d__47 <RemoteResetAsync>d__ = new MelsecMcNet.<RemoteResetAsync>d__47();
			<RemoteResetAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<RemoteResetAsync>d__.<>4__this = this;
			<RemoteResetAsync>d__.<>1__state = -1;
			<RemoteResetAsync>d__.<>t__builder.Start<MelsecMcNet.<RemoteResetAsync>d__47>(ref <RemoteResetAsync>d__);
			return <RemoteResetAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ReadPlcType" />
		// Token: 0x0600098C RID: 2444 RVA: 0x000379A4 File Offset: 0x00035BA4
		[DebuggerStepThrough]
		public Task<OperateResult<string>> ReadPlcTypeAsync()
		{
			MelsecMcNet.<ReadPlcTypeAsync>d__48 <ReadPlcTypeAsync>d__ = new MelsecMcNet.<ReadPlcTypeAsync>d__48();
			<ReadPlcTypeAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<string>>.Create();
			<ReadPlcTypeAsync>d__.<>4__this = this;
			<ReadPlcTypeAsync>d__.<>1__state = -1;
			<ReadPlcTypeAsync>d__.<>t__builder.Start<MelsecMcNet.<ReadPlcTypeAsync>d__48>(ref <ReadPlcTypeAsync>d__);
			return <ReadPlcTypeAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.Melsec.MelsecMcNet.ErrorStateReset" />
		// Token: 0x0600098D RID: 2445 RVA: 0x000379E8 File Offset: 0x00035BE8
		[DebuggerStepThrough]
		public Task<OperateResult> ErrorStateResetAsync()
		{
			MelsecMcNet.<ErrorStateResetAsync>d__49 <ErrorStateResetAsync>d__ = new MelsecMcNet.<ErrorStateResetAsync>d__49();
			<ErrorStateResetAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<ErrorStateResetAsync>d__.<>4__this = this;
			<ErrorStateResetAsync>d__.<>1__state = -1;
			<ErrorStateResetAsync>d__.<>t__builder.Start<MelsecMcNet.<ErrorStateResetAsync>d__49>(ref <ErrorStateResetAsync>d__);
			return <ErrorStateResetAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x0600098E RID: 2446 RVA: 0x00037A2C File Offset: 0x00035C2C
		public override string ToString()
		{
			return string.Format("MelsecMcNet[{0}:{1}]", this.IpAddress, this.Port);
		}

		/// <summary>
		/// 将MC协议的核心报文打包成一个可以直接对PLC进行发送的原始报文
		/// </summary>
		/// <param name="mcCore">MC协议的核心报文</param>
		/// <param name="networkNumber">网络号</param>
		/// <param name="networkStationNumber">网络站号</param>
		/// <returns>原始报文信息</returns>
		// Token: 0x0600098F RID: 2447 RVA: 0x00037A4C File Offset: 0x00035C4C
		public static byte[] PackMcCommand(byte[] mcCore, byte networkNumber = 0, byte networkStationNumber = 0)
		{
			byte[] array = new byte[11 + mcCore.Length];
			array[0] = 80;
			array[1] = 0;
			array[2] = networkNumber;
			array[3] = byte.MaxValue;
			array[4] = byte.MaxValue;
			array[5] = 3;
			array[6] = networkStationNumber;
			array[7] = (byte)((array.Length - 9) % 256);
			array[8] = (byte)((array.Length - 9) / 256);
			array[9] = 10;
			array[10] = 0;
			mcCore.CopyTo(array, 11);
			return array;
		}

		/// <summary>
		/// 从PLC反馈的数据中提取出实际的数据内容，需要传入反馈数据，是否位读取
		/// </summary>
		/// <param name="response">反馈的数据内容</param>
		/// <param name="isBit">是否位读取</param>
		/// <returns>解析后的结果对象</returns>
		// Token: 0x06000990 RID: 2448 RVA: 0x00037AC8 File Offset: 0x00035CC8
		public static OperateResult<byte[]> ExtractActualData(byte[] response, bool isBit)
		{
			OperateResult<byte[]> result;
			if (isBit)
			{
				byte[] array = new byte[response.Length * 2];
				for (int i = 0; i < response.Length; i++)
				{
					bool flag = (response[i] & 16) == 16;
					if (flag)
					{
						array[i * 2] = 1;
					}
					bool flag2 = (response[i] & 1) == 1;
					if (flag2)
					{
						array[i * 2 + 1] = 1;
					}
				}
				result = OperateResult.CreateSuccessResult<byte[]>(array);
			}
			else
			{
				result = OperateResult.CreateSuccessResult<byte[]>(response);
			}
			return result;
		}

		/// <summary>
		/// 检查从MC返回的数据是否是合法的。
		/// </summary>
		/// <param name="content">数据内容</param>
		/// <returns>是否合法</returns>
		// Token: 0x06000991 RID: 2449 RVA: 0x00037B44 File Offset: 0x00035D44
		public static OperateResult CheckResponseContent(byte[] content)
		{
			ushort num = BitConverter.ToUInt16(content, 9);
			bool flag = num > 0;
			OperateResult result;
			if (flag)
			{
				result = new OperateResult<byte[]>((int)num, MelsecHelper.GetErrorDescription((int)num));
			}
			else
			{
				result = OperateResult.CreateSuccessResult();
			}
			return result;
		}
	}
}
